package cn.iocoder.yudao.module.product.controller.app.property;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO;
import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueGroupReqVO;
import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueGroupRespVO;
import cn.iocoder.yudao.module.product.service.property.ProductPropertyValueService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "用户 APP - 商品属性值")
@RestController
@RequestMapping("/product/property/value")
@Validated
public class AppProductPropertyValueController {

    @Resource
    private ProductPropertyValueService productPropertyService;

    @GetMapping("/list-by-property-name")
    @Operation(summary = "通过属性名称查询有哪些属性值")
    public CommonResult<List<AppProductPropertyValueGroupRespVO>> listByPropertyName(@Valid AppProductPropertyValueGroupReqVO reqVO) {
        final List<ProductPropertyValueDetailRespDTO> dtoList = productPropertyService.getPropertyValueListByPropertyNameGroupByValue(reqVO.getPropertyName());
        final List<AppProductPropertyValueGroupRespVO> voList = BeanUtils.toBean(dtoList, AppProductPropertyValueGroupRespVO.class);
        return success(voList);
    }

}
